package cn.zh.npro.Adapter;

import android.content.Context;
import android.content.Intent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import java.util.ArrayList;

import cn.zh.npro.Activity.RepOd;
import cn.zh.npro.Item.OrItem;
import cn.zh.npro.MyApplication;
import cn.zh.npro.R;

/**
 * Created by WYN on 2018/3/5 0005.
 */

public class OrAdapter extends BaseAdapter {
   Context context;
   ArrayList<OrItem> arrayList;
   LayoutInflater inflater;
   MyApplication mapp;
   String customerID;
   public OrAdapter(Context context,ArrayList<OrItem> arrayList,MyApplication mapp){
       this.context=context;
       this.arrayList=arrayList;
       this.mapp=mapp;
       inflater=LayoutInflater.from(context);

       }


    @Override
    public int getCount() {
        return arrayList.size();
    }

    @Override
    public Object getItem(int i) {
        return arrayList.get(i);
    }

    @Override
    public long getItemId(int i) {
        return i;
     }

    @Override
    public View getView(final int i, View view, ViewGroup viewGroup) {
       Holder holder=null;
       if (null==view){
           view=inflater.inflate(R.layout.oritem_layout,null,false);
           holder=new Holder();
           holder.tntxt=view.findViewById(R.id.tntxt);
           holder.ortype=view.findViewById(R.id.ortype);
           holder.cntxt=view.findViewById(R.id.cntxt);
           holder.timtxt=view.findViewById(R.id.timtxt);
           holder.pricetxt=view.findViewById(R.id.pricetxt);

           view.setTag(holder);
        }else {
           holder= (Holder) view.getTag();
         }
        holder.tntxt.setText(arrayList.get(i).getTradeNO());
        holder.ortype.setText(arrayList.get(i).getTradeStatus());
        holder.cntxt.setText("客户名称："+arrayList.get(i).getCustomerName());
        String stim=arrayList.get(i).getTradeTime();
        final int index=stim.indexOf(".");
        if (-1==index){
        }else {
          stim=stim.substring(0,index);
          }
        stim=stim.replace("T"," ");
        holder.timtxt.setText(stim);
        holder.pricetxt.setText("订单金额 ¥"+arrayList.get(i).getGoodsTotal());
//        holder.again.setOnClickListener(new View.OnClickListener() {
//            @Override
//            public void onClick(View view) {
//                mapp.setTraId(arrayList.get(i).getTradeID());
//                Intent intent=new Intent(context,RepOd.class);
//                intent.putExtra("type","1");
//                intent.putExtra("ob",arrayList.get(i));
//                intent.putExtra("clId",customerID);
//                context.startActivity(intent);
//            }
//        });
        return view;
       }




    public class Holder{
    TextView tntxt,ortype,cntxt,timtxt,pricetxt,again;
     }


}
